@extends('home.layouts.app')

@section('title','我的')

<!-- 设置token -->
<meta name="csrf-token" content="{{csrf_token()}}">

@push('css')
<!-- 页面独立的 -->
<link rel="stylesheet/less" href="{{URL::asset('assets/css/UserIndex.less')}}" />
@endpush

@section('content')
<!-- 用户信息 -->
<div class="user">
    <div class="avatar wow fadeInUp">
        <img src="{{!empty($LoginUser['avatar']) ? URL::asset('uploads/'.$LoginUser['avatar']) : URL::asset('assets/images/avatar.png') }}" />
    </div>

    @if(request()->cookie('LoginUser'))
    <div class="nickname wow fadeInUp" data-wow-delay="100ms">{{!empty($LoginUser['nickname']) ? $LoginUser['nickname'] : '未设置昵称'}}</div>
    @endif

    @if(!request()->cookie('LoginUser'))
    <a href="{{url('home/user/login')}}" class="login wow fadeInUp" data-wow-delay="200ms">登录</a>
    @endif
</div>

<!-- 菜单 -->
<div class="menulist wow fadeInUp" data-wow-delay="300ms">
    <a href="{{url('home/user/profile')}}" class="item">
        <span>基本资料</span>
        <img src="{{URL::asset('assets/images/row.png')}}" />
    </a>
    @if(request()->cookie('LoginUser'))
    <a href="javascript:void(0)" class="item" id="logout">
        <span>退出</span>
        <img src="{{URL::asset('assets/images/row.png')}}" />
    </a>
    @endif
</div>

<!-- 底部导航 -->
@include('home.common.tabbar')
@endsection
@push('script')
<script>
   layui.use(['layer'],function(){
        var layer = layui.layer

        $('#logout').click(function(){
            layer.confirm('确认退出?',{
                title:'退出账号'
            },function(index){

                $.ajax({
                    type:'post',
                    url:`{{url('home/user/logout')}}`,
                    dataType:'json',
                    headers:{
                        'X-CSRF-TOKEN':$('meta[name="csrf-token"]').attr('content')
                    },
                    success:function(res)
                    {
                        if(res.code === 1)
                        {
                            layer.msg(res.msg,function(){
                                history.go(0)
                            })
                        }
                    }
                })

                layer.close(index)
            })
        })
   })

</script>
@endpush